package top.lgd.utils;

import cn.hutool.core.collection.CollectionUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author YYJ
 * @version 1.0
 * @since 2020/12/3 13:25
 */
public final class CollectionUtils extends CollectionUtil {

    public static <T> List<T> copy(List<?> sourceList, Class<T> targetClass) {
        if (isEmpty(sourceList)) {
            return Collections.emptyList();
        }

        List<T> targetList = new ArrayList(sourceList.size());
        sourceList.forEach(s -> {
            try {
                T target = targetClass.newInstance();
                BeanUtils.copyProperties(s, target);
                targetList.add(target);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        return targetList;
    }
}
